
import { Vue } from '../modules/vue/index.js';

const vm = new Vue({
  data () {
    return {
      a: 1,
      b: 2
    }
  },
  computed: {
    // descriptor.value
    total () {
      console.log('Computed');
      return this.a + this.b;
    },
    // descriptor.value.get 第二种写法
    // total: {
    //   get() {
    //     console.log('Computed');
    //     return this.a + this.b;
    //   }
    // }
  },
  watch: {
    total (newVal, oldVal) {
      console.log('total: ', newVal, oldVal);
    },
    a (newVal, oldVal) {
      console.log('a: ', newVal, oldVal);
    },
    b (newVal, oldVal) {
      console.log('b: ', newVal, oldVal);
    }
  }
});

console.log(vm);

console.log(vm.total);
console.log(vm.total);
console.log(vm.total);

vm.a = 100;

console.log(vm.total);
console.log(vm.total);
console.log(vm.total);

vm.b = 200;

console.log(vm.total);
console.log(vm.total);
console.log(vm.total);
